package org.examplexx.mytestwebapplication.controller;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.examplexx.mytestwebapplication.pojo.Dept;
import org.examplexx.mytestwebapplication.pojo.Result;
import org.examplexx.mytestwebapplication.service.DeptService;
import org.examplexx.mytestwebapplication.service.impl.DeptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.logging.Logger;
@Slf4j
//自动输出日志注解
@RestController
@RequestMapping("/depts")
//包含两个注解
//Get用于查询ID
//Put用于更新
public class DeptController {
    @Autowired
    private DeptService deptService;//注入接口
//    private static Logger logger = Logger.getLogger(String.valueOf(DeptController.class));
//    @RequestMapping(value = "/depts",method = RequestMethod.GET)//指定请求方式为GET
    @GetMapping
    public Result list(){
        log.info("查询部门数据");
        List<Dept> deptList=deptService.list();
        Result result = new Result();
        result.success(deptList);
        return result;
    }
    @DeleteMapping("/delete/{id}")
    //获取动态id 把id 绑定给id
    public Result delete(@PathVariable Integer id){
        deptService.delete(id);
        Result result = new Result();
        result.success();
        return result;
    }
    @PostMapping
    public void add(@RequestBody Dept dept){//json格式数据封装到Dept中
        deptService.add(dept);
    }
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        Result result = new Result();
        result.success(deptService.get(id));
        return result;
    }
    @PutMapping("/update")
    public void update(@RequestBody Dept dept){
        deptService.update(dept);
    }
}